﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using wathammer40kListBuilder.ViewModel;
using wh40klbModel;

namespace wathammer40kListBuilder.View
{
    /// <summary>
    /// Interaction logic for AdminArmy.xaml
    /// </summary>
    public partial class AdminArmy : UserControl
    {
        private AdminArmyViewModel viewModel;

        public AdminArmy()
        {
            InitializeComponent();

            viewModel = new AdminArmyViewModel();
            this.DataContext = viewModel;
        }

        private void AddInfantryButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (viewModel.SelectedArmy == null)
                {
                    MessageBox.Show("Vous devez selectionner une armée pour effectuer cette action");
                    return;
                }
                ModalWindow mw = new ModalWindow();
                if (mw == null) return;
                mw.AddPanel(new NewInfantry(viewModel.SelectedArmy));
                mw.ShowDialog();
                viewModel.majSelectedArmy();
            }
            catch (Exception)
            {
                MessageBox.Show("Une raison innatendue empeche la creation de'une nouvelle unitée");
            }
        }

        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBox cb = e.Source as ComboBox;
            if (cb == null) return;
            viewModel.SelectedArmy = cb.SelectedItem as Army;

        }

        private void DeleteInfantryButton_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult v= MessageBox.Show("", "Supression d'armée", MessageBoxButton.YesNo);
            if (v == MessageBoxResult.Yes)
            {
                viewModel.DeleteArmy();
            }
        }
    }
}
